#include "MiRpc.h"

#include <iostream>
int finish =0;
void foo(void* arg1, void* arg2, void *ctx)
{
    std::cout << "recv response!, "<< ++finish << std::endl;
}

void foo2(void* self,void* cb)
{

}
int main()
{
    RdmaRpc cli_rpc;
    cli_rpc.Init(NULL, 0, 128 << 10, RPC_SHARED_RECV_QUEUE);
    int cli_id = cli_rpc.ConnectSess("10.0.0.37:12345", foo2, NULL);
    struct RpcMsg* request = (struct RpcMsg *)cli_rpc.AllocMsg();
    cli_rpc.PrepareMsg(request, 0);
    request->data_len= 1024;
    cli_rpc.RpcCliWriteReq(cli_id, request, foo, NULL);
    int cnt =0;
    while(1)
    {
        //
        if(cli_rpc.RpcCliHandleRx() > 0)
        {
            cli_rpc.FreeMsg(request);
            if(cnt < 1000000){
                request = (struct RpcMsg *)cli_rpc.AllocMsg();
                cli_rpc.PrepareMsg(request, 0);
                request->data_len=1024;
                cli_rpc.RpcCliWriteReq(cli_id, request, foo, NULL);
                cnt++;
            }
            else{
                cli_rpc.CloseSess(cli_id);
                break;
            }
        }
        cli_rpc.RpcCliHandleTx();
    }
    while(cli_rpc.RpcCliHandleRx() <= 0)
    {
        cli_rpc.RpcCliHandleTx();
    }
    cli_rpc.Destroy();
    std::cout << "client closed..." << std::endl; 
    return 0;
}